package com.zhsource.article.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhsource.article.domain.FriendAddress;
import com.zhsource.article.mapper.FriendAddressMapper;
import com.zhsource.article.query.FriendAddressQuery;
import com.zhsource.article.service.IFriendAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>@ClassName：FriendAddressServiceImpl
 * <p>@Date 2023/10/17  13:01
 *
 * @Author zzl
 **/
@Service
public class FriendAddressServiceImpl implements IFriendAddressService {

    @Autowired
    private FriendAddressMapper friendAddressMapper;

    @Override
    public List<FriendAddress> list() {
        return friendAddressMapper.list();
    }

    @Override
    public FriendAddress selectById(Long id) {
        return friendAddressMapper.selectById(id);
    }

    @Override
    public PageInfo<FriendAddress> page(FriendAddressQuery friendAddressQuery) {
        // 1.下面这句代码表示开启分页，会将紧挨着这句代码的下一次数据库执行进行分页，切记一定要放在要分页的SQL语句前面执行
        PageHelper.startPage(friendAddressQuery.getCurrentPage(), friendAddressQuery.getPageSize());

        // 2.执行SQL语句带条件查询，SQL语句不需要进行分页
        List<FriendAddress> page = friendAddressMapper.page(friendAddressQuery);
        // 3.将查询结果转换为PageInfo对象，PageInfo对象中有前端分页所需要的各种参数
        PageInfo<FriendAddress> pageInfo = new PageInfo<>(page);
        // 4.响应总条数和分页信息
        return pageInfo;
    }

    @Override
    public void update(FriendAddress friendAddress) {
        // 1. 修改用户信息
        friendAddressMapper.update(friendAddress);
    }
    @Override
    public void insert(FriendAddress friendAddress) {
        // 1. 新增员工
        friendAddressMapper.insert(friendAddress);
    }
    @Override
    public void delete(Long id) {
        friendAddressMapper.delete(id);

    }

    @Override
    public void batchDel(List<Long> ids) {

        friendAddressMapper.batchDel(ids);


    }

    @Override
    public List<FriendAddress> getFriendAddress() {
        return friendAddressMapper.getFriendAddress();
    }
}
